//
//  DEWAnswerView.m
//  OtherDemo
//
//  Created by kangbinbin on 2018/7/28.
//  Copyright © 2018年 lianjie. All rights reserved.
//

#import "DEWAnswerView.h"
#import "MBProgressHUD+Add.h"

@implementation DEWAnswerView

-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame: frame]) {

    }
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    self.AnswerTextView.placeholder = @"我来说一说";
    self.AnswerTextView.layer.cornerRadius = 3;
    self.sendBtn.layer.cornerRadius = 3;
    self.sendBtn.layer.borderColor = UIColorFromRGB(0x999999).CGColor;
    self.sendBtn.layer.borderWidth = 1;
    self.cancelBtn.layer.cornerRadius = 3;
    self.cancelBtn.layer.borderColor = UIColorFromRGB(0x999999).CGColor;
    self.cancelBtn.layer.borderWidth = 1;
//    [self.AnswerTextView becomeFirstResponder];
}


#pragma mark - 向下的箭头按钮点击事件
- (IBAction)DownBtnClick:(UIButton *)sender {
    NSLog(@"点击箭头");
    [self closeView];
}
#pragma mark - 发布按钮点击事件
- (IBAction)sendBtnClick:(UIButton *)sender {
    NSLog(@"点击发布按钮");
    if ([self.AnswerTextView.text isEqualToString:@""]) {
        [MBProgressHUD showSuccess:@"请填写你的内容" toView:[UIApplication sharedApplication].keyWindow];
    }
    if (self.sendBtnBlock) {
        self.sendBtnBlock(self.AnswerTextView.text);
    }
}
-(void)show{
    self.alpha = 0;
    [UIView animateWithDuration:0.05 animations:^{
        self.alpha = 1;
//        [self.AnswerTextView becomeFirstResponder];
    }];
}
#pragma mark - 取消按钮点击事件
- (IBAction)cancelBtnClick:(UIButton *)sender {
    NSLog(@"点击取消按钮");
    [self closeView];
}
-(void)closeView{
    [UIView animateWithDuration:0.5 animations:^{
        self.alpha = 0;
    } completion:^(BOOL finished) {
        [self removeFromSuperview];
    }];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    UITouch *touch = [touches anyObject];
    CGPoint pt = [touch locationInView:self];
    if (!CGRectContainsPoint([self frame],  pt)) {
//        [self closeView];
//        [self.AnswerTextView resignFirstResponder];
    }
    
}

@end
